<!doctype html>


<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>bidiformatter.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>





<div class="colmask rightmenu">
<div class="colleft">
    <div class="col1">
      <!-- Column 1 start -->

<div id="title">
       <span class="fn">bidiformatter.js</span>
</div>

<div class="g-section g-tpl-75-25">
  <div class="g-unit g-first" id="description">
    <span class='nodesc'>No description.</span>
  </div>
  

        <div class="g-unit" id="useful-links">
          <div class="title">Useful links</div>
          <ol>
            <li><a href="local_closure_goog_i18n_bidiformatter.js.source.html"><span class='source-code-link'>Source Code</span></a></li>
            <li><a href="http://code.google.com/p/closure-library/source/browse/local/closure/goog/i18n/bidiformatter.js">Git</a></li>
          </ol>
        </div>
</div>

<h2 class="g-first">File Location</h2>
  <div class="g-section g-tpl-20-80">
    <div class="g-unit g-first">
      <div class="g-c-cell code-label">/goog/i18n/bidiformatter.js</div>
    </div>
  </div>
<hr/>


  <h2>Classes</h2>
 <div class="fn-constructor">
        <a href="class_goog_i18n_BidiFormatter.html">
          goog.i18n.BidiFormatter</a><br/>
        <div class="class-details">Utility class for formatting text for display in a potentially
opposite-directionality context without garbling. Provides the following
functionality:

1. BiDi Wrapping
When text in one language is mixed into a document in another, opposite-
directionality language, e.g. when an English business name is embedded in a
Hebrew web page, both the inserted string and the text following it may be
displayed incorrectly unless the inserted string is explicitly separated
from the surrounding text in a "wrapper" that declares its directionality at
the start and then resets it back at the end. This wrapping can be done in
HTML mark-up (e.g. a 'span dir="rtl"' tag) or - only in contexts where
mark-up can not be used - in Unicode BiDi formatting codes (LRE|RLE and PDF).
Providing such wrapping services is the basic purpose of the BiDi formatter.

2. Directionality estimation
How does one know whether a string about to be inserted into surrounding
text has the same directionality? Well, in many cases, one knows that this
must be the case when writing the code doing the insertion, e.g. when a
localized message is inserted into a localized page. In such cases there is
no need to involve the BiDi formatter at all. In the remaining cases, e.g.
when the string is user-entered or comes from a database, the language of
the string (and thus its directionality) is not known a priori, and must be
estimated at run-time. The BiDi formatter does this automatically.

3. Escaping
When wrapping plain text - i.e. text that is not already HTML or HTML-
escaped - in HTML mark-up, the text must first be HTML-escaped to prevent XSS
attacks and other nasty business. This of course is always true, but the
escaping can not be done after the string has already been wrapped in
mark-up, so the BiDi formatter also serves as a last chance and includes
escaping services.

Thus, in a single call, the formatter will escape the input string as
specified, determine its directionality, and wrap it as necessary. It is
then up to the caller to insert the return value in the output.

See <a href="http://wiki/Main/TemplatesAndBiDi">http://wiki/Main/TemplatesAndBiDi</a> for more information.

</div>
 </div>
      









<div class="section">
  <table class="horiz-rule">


  </table>
</div>










      <!-- Column 1 end -->
    </div>

        <div class="col2">
          <!-- Column 2 start -->
          <div class="col2-c">
            <h2 id="ref-head">Directory i18n</h2>
            <div id="localView"></div>
          </div>

          <div class="col2-c">
            <h2 id="ref-head">File Reference</h2>
            <div id="sideFileIndex" rootPath="" current="/goog/i18n/bidiformatter.js"></div>
          </div>
          <!-- Column 2 end -->
        </div>
</div>
</div>

</body>
</html>
